﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}

@section CssJs{
    <script type="text/javascript" charset="utf-8" src="/js/laytpl.js"></script>
    <script type="text/javascript" charset="utf-8" src="/js/laypage.js"></script>
}

<div class="main-wrap">

    <div class="crumb-wrap">
        <div class="crumb-list"><i class="icon-font"></i><a href="@(Url.Action("Index","Home"))">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">评论管理</span></div>
    </div>
    <div class="search-wrap">
        <div class="search-content">
            <form action="#" method="post">
                <table class="search-tab">
                    <tr>
                        <th width="120">评论状态:</th>
                        <td>
                            <select name="status" id="status">
                                <option value="1">待审核</option>
                                <option value="0">已审核</option>
                                <option value="2">审核失败</option>
                            </select>
                        </td>
                        <th width="70">关键字:</th>
                        <td><input class="common-text" placeholder="关键字" name="keyword" value="" id="keyword" type="text"></td>
                        <td><input class="btn btn-primary btn2" name="sub" value="查询" id="submit" type="button"></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <div class="result-wrap">
        <form name="myform" id="myform" method="post">
            <div class="result-title">
                <div class="result-list">
                    
                    <a id="batchRecovery" v="Recovery" href="javascript:void(0)"><i class="icon-font">&#xe010;</i>恢复</a>
                    <a id="batchCheck" v="Check" href="javascript:void(0)"><i class="icon-font">&#xe025;</i>审核</a>
                    <a id="batchUnCheck" v="UnCheck" href="javascript:void(0)"><i class="icon-font">&#xe00A;</i>取消审核</a>
                    <a id="batchDel" v="Del" href="javascript:void(0)"><i class="icon-font">&#xe061;</i>删除</a>
                </div>
            </div>
            <div class="result-content">
                <table class="result-tab" width="100%">
                    <tr>
                        <th class="tc" width="5%"><input class="allChoose" name="checkAll" id="checkAll" type="checkbox"></th>
                        <th>ID</th>
                        <th>评论内容</th>
                        <th>文章</th>
                        <th>发布人</th>
                        <th>邮箱</th>
                        <th>网站</th>
                        <th>发布时间</th>
                    </tr>
                    <tbody id="tbody"></tbody>
                </table>
                <div class="list-page" id="page"> 2 条 1/1 页</div>
            </div>
        </form>
    </div>
</div>

<script id="list" type="text/html">
    {{# for(var i = 0, len = d.length; i < len; i++){ }}
    <tr>
        <td class="tc"><input name="checkname" value="{{ d[i].id }}" type="checkbox"></td>
        <td>
            <input name="Id" value="{{ d[i].id }}" type="hidden">
            {{ d[i].id }}
        </td>
        <td><pre>{{ $('<span />').text(d[i].content).html() }}</pre></td>
        <td>
            <a href="/Admin/Article/Add/{{ d[i].articleId }}">{{ d[i].title }}</a>
        </td>
        <td>{{ d[i].nickName }}</td>
        <td>{{ d[i].email||"" }}</td>
        <td>{{ d[i].url||"" }}</td>
        <td>{{ d[i].postDate }}</td>
    </tr>
    {{# } }}
</script>
<script>
    var pageIndex = 1;
    $(function () {
        GetCommentPager();

        $("#checkAll").click(
            function () {
                if (this.checked) {
                    $("input[name='checkname']").prop('checked', true);
                } else {
                    $("input[name='checkname']").prop('checked', false);
                }
            }
        );

        $(".result-list a").click(function () {
            var action = $(this).attr("v");
            var ids = $("input[name='checkname']:checked").map(function () { return this.value; }).get();
            if (ids.length == 0) {
                return;
            }
            $.ajax({
                type: "POST",
                url: "@(Url.Action("Update", "Comment"))",
                data: { ids: ids, action: action },
                traditional:true,//数组参数不带[]
                success: function (result) {
                    if (result.errorMessage) {
                        var error = result.errorMessage;
                        if (result.data) {
                            error += "<br>" + result.data;
                        }
                        layer.alert(error, { icon: 5 }, function() {
                            location.reload();
                        });
                    } else {
                        location.reload();
                    }
                }
            });
        });

        $("#submit").click(function () {
            pageIndex = 1;
            GetCommentPager();
        });

    });

    function CheckStatus(status) {
        switch (status) {
            case 0://已审核
                $("#batchCheck").hide();
                $("#batchUnCheck").show();
                $("#batchDel").hide();
                $("#batchRecovery").hide();

                break;
            case 1://待审核
                $("#batchCheck").show();
                $("#batchUnCheck").hide();
                $("#batchDel").show();
                $("#batchRecovery").hide();
                break;
            case 2://审核失败
                $("#batchCheck").hide();
                $("#batchUnCheck").hide();
                $("#batchDel").show();
                $("#batchRecovery").show();
                break;
        }
    }

    function GetCommentPager() {
        var status = $("#status").val();
        var keyword = $("#keyword").val();
        CheckStatus(status * 1);
        $.ajax({
            type: "POST",
            url: "@(Url.Action("GetPageInfo", "Comment"))",
            data: { pageIndex: pageIndex, status: status, keyword: keyword },
            success: function (result) {
                if (result.status) {
                    laytpl($("#list").html()).render(result.data.list, function (html) {
                        $("#tbody").html(html);
                    });
                    laypage({
                        cont: 'page',
                        pages: result.data.pageCount,
                        curr: pageIndex||1,
                        jump: function (obj, first) {
                            if (!first) {
                                pageIndex = obj.curr;
                                GetCommentPager();
                            }
                        }
                    });
                } else {
                    var error = result.errorMessage;
                    if (result.data) {
                        error += "<br>" + result.data;
                    }
                    layer.alert(error, { icon: 5 });
                }
            }
        });
    }
</script>